<!DOCTYPE html>
<!--suppress ThymeleafVariablesResolveInspection-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="Responsive Admin Dashboard Template">
        <meta name="keywords" content="admin,dashboard">
        <meta name="author" content="skcats">
		<title></title>
		<link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all" />
        <link th:href="@{/assets/plugins/bootstrap/css/bootstrap.min.css}" rel="stylesheet">
        <link th:href="@{/assets/plugins/font-awesome/css/font-awesome.min.css}" rel="stylesheet">
        <link th:href="@{/assets/css/custom.css}" rel="stylesheet">
	</head>
	<style>
     ::-webkit-scrollbar {display:none}/*隐藏横向滚动条但可以滚动*/
     .layui-table-page {
         text-align: center;
     }

     .utable .layui-laypage .layui-laypage-curr .layui-laypage-em {
         background-color: #1E9FFF;
     }
     .layui-input-inline{margin-left: 50px;}
     .layui-form-item{margin-top: 20px;}
     .layui-form-label{width: 80px;}
     .layui-table-view thead th {
         text-align: center;
         font-weight: bold;
     }
     .layui-table-view tbody td {
         text-align: center;
     }
     .layui-table {
         text-align: center;
         margin-top: -10px;
     }
	</style>
<body>
<!--数据表格样式及附件-->
<script id="toolbarDemo" type="text/html">
    <div class="layui-btn-container">
        <button id="return" class="layui-btn layui-btn-sm"><i class="layui-icon"style="font-size: 20px">&#xe65c;</i></button>
        <button id="echarts" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe62c;图表</i></button>
    </div>
</script>

<input id="scoreid" type="hidden" th:value="${scoreid}"/>

<!--表格-->
<div class="utable">
    <table class="layui-table" id="tab" lay-filter="tab"></table>
</div>

</body>
<script th:src="@{/assets/plugins/jquery/jquery-3.1.0.min.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:inline="none">

    layui.use('table', function () {
        var table = layui.table;
        var scoreid = $("#scoreid").val();
        //方法渲染
        table.render({
            elem: '#tab'
            ,id: 'tab'
            ,height: 520
            ,width: 1250
            ,url: '/classscore/studata?scoreid='+scoreid//数据接口
            ,page: true //开启分页
            ,toolbar: '#toolbarDemo'
            ,cols: [[ //表头
                {field: 'ssid', title: '编号', sort: true}
                ,{field: 'stuname', title: '学生名称'}
                ,{field: 'scure', title: '学生成绩',edit:true,sort: true}
                ,{field: 'rescore', title: '补考成绩',edit:true,sort: true}
                ,{field: 'remark', title: '备注',edit:true}
            ]]
        });


        //点击添加iframe窗方法
        $("#return").on('click',function(){
            document.location.href="/skip/classscorelist"
        })

        $("#echarts").on('click',function(){
            document.location.href="/skip/stuscorechart?id="+scoreid;
        })

        //监听单元格编辑（修改）
        table.on('edit(tab)', function(obj){
            var tr = obj.tr;
            // 单元格编辑之前的值
            var oldtext = $(tr).find("td[data-field='"+obj.field+"'] div").text();
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            if(isNaN(data.scure)){
                    layer.msg(JSON.stringify("请输入正确的数字"));
                    $('.layui-laypage-btn').click();
                    return;
            } else {
                $.ajax({
                    url: '/classscore/stuupd',
                    type: 'post',
                    data: {
                        ssid:data.ssid,
                        scure:data.scure,
                        rescore:data.rescore,
                        remark:data.remark
                    },
                    dataType: 'json',
                    success:function(data){
                        if(data){
                            layer.msg(JSON.stringify("修改成功"));
                        }
                    },
                })
            }
        });


    });
</script>
</html>